
#include "Camera.h"

Camera::Camera(void)
{
	mCameraType = AIRCRAFT;

	mPos = Vector3<float>(0.0f,0.0f,0.0f);
	mRight = Vector3<float>(1.0f,0.0f,0.0f);
	mUp = Vector3<float>(0.0f,1.0f,0.0f);
	mLook = Vector3<float>(0.0f,0.0f,1.0f);

	}

Camera::Camera(CameraType cameraType)
{
	mCameraType = cameraType;
	mPos = Vector3<float>(0.0f,0.0f,0.0f);
	mRight = Vector3<float>(1.0f,0.0f,0.0f);
	mUp = Vector3<float>(0.0f,1.0f,0.0f);
	mLook = Vector3<float>(0.0f,0.0f,1.0f);

}

Camera::~Camera(void)
{

}

void Camera::GetPosition(vmath::Vector3<float> *vector3)
{
	*vector3 = mPos;
}

void Camera::SetPosition(vmath::Vector3<float> *vector3)
{
	mPos = *vector3;
}

void Camera::GetRight(vmath::Vector3<float> *vector3)
{
	*vector3 = mRight;
}
void Camera::GetUp(vmath::Vector3<float> *vector3)
{
	*vector3 = mUp;
}

void Camera::GetLook(vmath::Vector3<float> *vector3)
{
	*vector3 = mLook;
}

void Camera::walk(float units)
{
	if(mCameraType == LANDOBJECT)
		mPos += Vector3<float>(mLook.x, 0.0f, mLook.z) * units;
	else if(mCameraType == AIRCRAFT)
		mPos += mLook * units;
}

void Camera::Strafe(float units)
{
	if(mCameraType == LANDOBJECT)
		mPos += Vector3<float>(mRight.x, 0.0f, mRight.z) * units;
	else if(mCameraType == AIRCRAFT)
		mPos += mRight * units;
}

void Camera::Fly(float units)
{
	if(mCameraType == LANDOBJECT)
		mPos += Vector3<float>(mUp.x, 0.0f, mUp.z) * units;
	else if(mCameraType == AIRCRAFT)
		mPos += mUp * units;

}

void Camera::GetViewMatrix(vmath::Matrix4<float> *viewMatrix)
{
	*viewMatrix = vmath::lookat_matrix(mLook,mPos,mUp);
}

void Camera::UpdateCamera()
{
	//vmath::Matrix4<float> viewMatrix;
	//GetViewMatrix(&viewMatrix);

	gluLookAt(mLook.x, mLook.y, mLook.z,mPos.x, mPos.y, mPos.z, mUp.x, mUp.y,mUp.z);
/*	glMatrixMode(GL_MODELVIEW);
	glLoadMatrixf(&viewMatrix);
*/
}